package com.example.backend.controller;

import com.example.backend.common.ResultMessage;
import com.example.backend.entity.PeiSong;
import com.example.backend.entity.vo.ShowQs;
import com.example.backend.service.impl.PeiSongService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/peisong")
public class PeiSongController {
    @Resource
    private PeiSongService peiSongService;

    /**
     * 添加配送信息
     */
    @PostMapping
    public ResultMessage addPsks(@RequestBody PeiSong peiSong) {
        peiSongService.addPsks(peiSong);
        return ResultMessage.success(peiSong, "配送信息添加成功");
    }

    /**
     * 删除已送达的配送订单信息
     */
    @DeleteMapping
    public ResultMessage deletePsdd(@RequestBody PeiSong peiSong) {
        if(peiSongService.deletePsdd(peiSong)){
            return ResultMessage.success(null,"配送订单信息删除成功");
        }
        return ResultMessage.error("配送订单信息删除失败");

    }

    /**
     * 修改配送信息
     */
    @PutMapping
    public ResultMessage updatePsdd(@RequestBody PeiSong peiSong){
        peiSongService.updatePsdd(peiSong);
        return ResultMessage.success(peiSong,"配送信息修改成功");
    }

    /**
     * 根据配送id查询配送信息
     */
    @GetMapping("/{psid}")
    public ResultMessage queryPsddBypsid(@PathVariable Integer psid) {
        PeiSong result = peiSongService.queryPsddBypsid(psid);
        return ResultMessage.success(result,"查询成功");
    }

    /**
     * 根据订单id查询配送信息
     */
    @GetMapping("/byddid/{ddid}")
    public ResultMessage queryPsddByddid(@PathVariable("ddid") Integer ddid) {
        return ResultMessage.success(peiSongService.queryPsddByddid(ddid),"查询成功");
    }

    /**
     * 查询所有配送信息
     */
    @GetMapping
    public ResultMessage queryPsdd() {
        // 查询所有配送信息
        List<PeiSong> results = peiSongService.queryPsdd();
        return ResultMessage.success(results,"查询成功");
    }

    /**
     * 更新配送状态
     */
    @PutMapping("/pszt")
    public ResultMessage updatePszt(@RequestBody PeiSong peiSong){
        if(peiSongService.updatePszt(peiSong)){
            return ResultMessage.success(peiSong,"更新成功");
        }
        return ResultMessage.error("更新失败");
    }

    /**
     * 查询所有已出餐的配送表信息
     */
    @GetMapping("/all")
    public ResultMessage queryPsWithPszt() {
        List<ShowQs> results = peiSongService.queryPsWithPszt();
        return ResultMessage.success(results,"查询成功");
    }



    /**
     * 通过骑手id查询自己在配送中的配送表信息
     */
    @GetMapping("/psing/{qsid}")
    public ResultMessage queryPsing(@PathVariable Integer qsid) {
        List<ShowQs> results = peiSongService.queryPsing(qsid);
        return ResultMessage.success(results,"查询成功");
    }

    /**
     * 通过骑手id查询自己所有已完成的配送表信息
     */
    @GetMapping("/success/{qsid}")
    public ResultMessage querySuccess(@PathVariable Integer qsid) {
        List<ShowQs> results = peiSongService.querySuccess(qsid);
        return ResultMessage.success(results,"查询成功");
    }

}
